{extend name="Base/common"/}

{block name="left"}
<div class="logo"></div>
<div class="menu">
  <a href="{:url('login')}">登录</a>
  <a class="active" href="{:url('register')}">注册</a>
</div>
<form class="login-form">
  <input type="text" id="inputEmail" name="username" placeholder="请输入用户名"/>
  <input type="password" id="inputPassword" name="password" placeholder="请输入密码"/>
  <input type="password" name="repassword" placeholder="请再次输入密码" recheck="password"/>
  <input type="text" id="inputEmail" placeholder="请输入电子邮件" name="email">
  <input type="text" name="verify" placeholder="验证码"/>
  
  <div class="controls verifyimg">
    {:captcha_img()}
  </div>
  <div class="Validform_checktip text-warning"></div>
  <button type="submit" class="btn">登 陆</button>
</form>
{/block}

{block name="script"}
	<script type="text/javascript">
    	$(document)
	    	.ajaxStart(function(){
	    		$("button:submit").addClass("log-in").attr("disabled", true);
	    	})
	    	.ajaxStop(function(){
	    		$("button:submit").removeClass("log-in").attr("disabled", false);
	    	});


    	$("form").submit(function(){
    		var self = $(this);
    		$.post(self.attr("action"), self.serialize(), success, "json");
    		return false;

    		function success(data){
    			if(data.code){
    				window.location.href = data.url;
    			} else {
    				self.find(".Validform_checktip").text(data.msg);
    				//刷新验证码
    				$(".verifyimg img").click();
    			}
    		}
    	});

		$(function(){
      //刷新验证码
        var verifyimg = $(".verifyimg img").attr("src");
        $(".verifyimg img").click(function(){
            if( verifyimg.indexOf('?')>0){
                $(".verifyimg img").attr("src", verifyimg+'&random='+Math.random());
            }else{
                $(".verifyimg img").attr("src", verifyimg.replace(/\?.*$/,'')+'?'+Math.random());
            }
        }); 
    });
	</script>
{/block}
